Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.pvzChannelTT = undefined;
var $2pvzChannelWeb = require("pvzChannelWeb");
var $2kc = require("kc");
var $2KDefine = require("KDefine");
var $2tt_analytics = require("tt_analytics");
var exp_pvzChannelTT = /* */function (_n$pvzChannelWeb3) {
  babel_inherits(l, _n$pvzChannelWeb3);
  var _super112 = babel_createSuper(l);
  function l() {
    var _this268;
    babel_classCallCheck(this, l);
    _this268 = _super112.apply(this, arguments);
    _this268.channel = "tt";
    _this268.paraMap = new Map([["bannerAd", "1j50igfcg8j6180g7f"], ["insertAd", "ol74jng159n1cbjgc0"], ["vedioAd", "4f2ipgnugsk1da7g82"], ["ctrlId", "6434fb1cece27854d5762431"]]);
    _this268.channelObj = window.tt;
    _this268.sdkData = null;
    _this268.startRecorderTime = 0;
    _this268.endRecorderTime = 0;
    _this268.video_path = null;
    _this268.videoTopics = ["花花大冒险"];
    _this268.title = "花花大冒险";
    return _this268;
  }
  babel_createClass(l, [{
    key: "getSysInfo",
    value: function getSysInfo() {
      this.sysInfo || (this.sysInfo = this.channelObj.getSystemInfoSync());
      return this.sysInfo;
    }
  }, {
    key: "exit",
    value: function exit() {
      this.channelObj.exitMiniProgram({
        isFullExit: true
      });
    }
  }, {
    key: "init",
    value: function init() {
      var _this269 = this;
      babel_get(babel_getPrototypeOf(l.prototype), "init", this).call(this);
      var e = this.getPara("ctrlId");
      if (e) {
        var _t96 = {
          id: e
        };
        $2kc.default.jpost("https://ga.gametdd.com/adCtrl/agd/conf", _t96, function (e, t) {
          if (e) {
            $2kc.default.err(e);
          } else if ("" + t.code == "0") {
            _this269.ctrl = t.data;
            $2kc.default.log("返回", _this269.ctrl);
          } else {
            $2kc.default.err("返回值错误:" + JSON.stringify(t));
          }
        });
      }
      var t = $2kc.default.getData("lastOpenTime", "");
      if (!(t && $2kc.default.todayStr() == t)) {
        $2kc.default.saveData("videoWatchTimes", 0);
        $2kc.default.saveData("lastOpenTime", $2kc.default.todayStr());
      }
      var a = this.channelObj.getLaunchOptionsSync().query;
      $2kc.default.log("【getLaunchOptionsSync】:", a);
      l.API_clickid = $2kc.default.getData("clickid", null);
      l.videoWatchTimes = parseInt($2kc.default.getData("videoWatchTimes", 0));
      $2kc.default.log("videoWatchTimes:" + l.videoWatchTimes + ", lastOpenTime:" + t);
      if (!l.API_clickid && a && a.clickid) {
        l.API_clickid = a.clickid;
        $2kc.default.log("【API_clickid】:" + l.API_clickid);
      }
      var n = this;
      tt.login({
        force: true,
        success(e) {
          console.log("login 调用成功", e.code);
          var t = tt.getLaunchOptionsSync();
          if (!l.API_clickid) {
            return;
          }
          var a = t.query.promotionid ? t.query.promotionid : "";
          var i = e.code;
          $2tt_analytics.init(i, "花花大冒险", l.API_clickid, a, function (e) {
            console.log("tt_analytics初始化成功", e);
            n.sdkData = e;
          }, function (e) {
            console.log("tt_analytics初始化失败" + e.msg);
          });
        },
        fail(e) {
          console.log("login 调用失败");
        }
      });
    }
  }, {
    key: "apiReport",
    value: function apiReport(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
      if (!l.API_clickid || !this.sdkData) {
        return void $2kc.default.log("【apiReport】API_clickid不存在或SDK未初始化完成!");
      }
      $2kc.default.log("【apiReport】类型:" + e);
      if (e === l.API_EventType.active_register) {
        $2kc.default.log("准备上报注册", this.sdkData.ecpm, this.sdkData.adCount);
        return void $2tt_analytics.register(function (e) {
          console.log("注册成功", e);
        }, function (e) {
          console.log("注册失败", e);
        });
      }
      $2kc.default.log("准备上报关键行为", this.sdkData.ecpm, this.sdkData.adCount, l.videoWatchTimes);
      $2tt_analytics.game_addiction(function (e) {
        console.log("关键行为成功", e);
      }, function (e) {
        console.log("关键行为失败", e);
      });
    }
  }, {
    key: "videoWathed",
    value: function videoWathed() {
      l.videoWatchTimes++;
      $2kc.default.saveData("videoWatchTimes", l.videoWatchTimes);
    }
  }, {
    key: "showBanner",
    value: function showBanner(e, t, a) {
      var _this270 = this;
      var n = this.getPara("bannerAd");
      if (!n) {
        return;
      }
      $2kc.default.log("showBanner isShow", n);
      var s = this.channelObj;
      var o = {
        adUnitId: n
      };
      this.bannerAd = s.createBannerAd(o);
      this.bannerAd.onResize(function (e) {
        console.log("banner onResize===", e.height, e.width);
        var a = t ? t(e) : {
          top: _this270.getSysInfo().windowHeight - e.height,
          left: (_this270.getSysInfo().windowWidth - e.width) / 2
        };
        _this270.bannerAd.style.top = a.top;
        _this270.bannerAd.style.left = a.left;
      });
      this.bannerAd.onLoad(function () {
        _this270.bannerAd.show().then(function () {
          $2kc.default.log("banner加载成功");
        }).catch(function (e) {
          _this270.bannerAd = null;
          $2kc.default.log("showBanner err:" + JSON.stringify(e));
        });
      });
    }
  }, {
    key: "closeBanner",
    value: function closeBanner() {
      if (this.bannerAd) {
        this.bannerAd.destroy();
        this.bannerAd = null;
      }
    }
  }, {
    key: "copyToClip",
    value: function copyToClip(e, t) {}
  }, {
    key: "showVideo",
    value: function showVideo(e) {
      var _this271 = this;
      var t = this.getPara("vedioAd");
      if (!t) {
        $2kc.default.log("无videoId,按成功执行");
        e.sucCall();
        return void e.endCall();
      }
      $2kc.default.log("showVideo", t, this.rewardedVideoAd);
      // this.rewardedVideoAd = this.channelObj.createRewardedVideoAd({
      //   adUnitId: t
      // });
       this.rewardedVideoAd = this.channelObj.createRewardedVideoAd({
        adUnitId: "11qhdojmj368604vb6"
      });
      this.videoFns.onLoad && this.rewardedVideoAd.offLoad(this.videoFns.onLoad);
      this.videoFns.onError && this.rewardedVideoAd.offError(this.videoFns.onError);
      this.videoFns.onClose && this.rewardedVideoAd.offClose(this.videoFns.onClose);
      this.rewardedVideoAd.offLoad();
      this.rewardedVideoAd.offError();
      this.rewardedVideoAd.offClose();
      var a = this;
      a.videoFns.onLoad = function () {
        $2kc.default.log("激励视频 广告加载成功");
      };
      a.videoFns.onError = function (t) {
        $2kc.default.err(t);
        e.failCall();
        a.channelObj.showToast({
          title: "暂无广告"
        });
      };
      a.videoFns.onClose = function (t) {
        if (t && t.isEnded) {
          e.sucCall();
          _this271.videoWathed();
          _this271.apiReport(l.API_EventType.game_addiction);
        }
        e.endCall();
      };
      a.rewardedVideoAd.onLoad(a.videoFns.onLoad);
      a.rewardedVideoAd.onError(a.videoFns.onError);
      a.rewardedVideoAd.onClose(a.videoFns.onClose);
      a.rewardedVideoAd.show().then(function () {
        $2kc.default.log("激励视频 广告显示");
      }).catch(function (e) {
        $2kc.default.err(e);
        a.rewardedVideoAd.load().then(function () {
          $2kc.default.log("手动加载成功");
          return a.rewardedVideoAd.show();
        });
      });
    }
  }, {
    key: "showInter",
    value: function showInter(e) {
      var t = this.getPara("insertAd");
      if (!t) {
        return;
      }
      var a = this.channelObj;
      $2kc.default.log("showInter isShow", t);
      // this.interstitialAd = a.createInterstitialAd({
      //   adUnitId: t
      // });
       this.interstitialAd = a.createInterstitialAd({
        adUnitId: "1j66nga7w9ui63624e"
      });
      this.interstitialAd.show().then(function () {
        $2kc.default.log("插屏广告展示完成");
      }).catch(function (e) {
        $2kc.default.log("插屏广告展示失败" + JSON.stringify(e));
      });
    }
  }, {
    key: "closeInter",
    value: function closeInter() {
      this.interstitialAd && this.interstitialAd.close && this.interstitialAd.close();
    }
  }, {
    key: "addShortcut",
    value: function addShortcut() {
      this.channelObj.addShortcut({
        success() {
          $2kc.default.log("添加桌面成功");
        },
        fail(e) {
          $2kc.default.log("添加桌面失败:" + e.errMsg);
        }
      });
    }
  }, {
    key: "recorderStart",
    value: function recorderStart() {
      $2kc.default.log("录屏====start");
      var e = this;
      e.channelObj.getGameRecorderManager().onStart(function () {
        e.startRecorderTime = Date.now();
        $2kc.default.log("录屏开始", e.startRecorderTime);
      });
      e.channelObj.getGameRecorderManager().start({
        duration: 300
      });
      $2kc.default.sendMsg($2KDefine.Msg.recorderStart);
    }
  }, {
    key: "recorderStop",
    value: function recorderStop() {
      var e = this;
      e.endRecorderTime = Date.now();
      $2kc.default.log("录屏Stop", e.endRecorderTime);
      e.channelObj.getGameRecorderManager().onStop(function (t) {
        e.video_path = t.videoPath;
        e.endRecorderTime = Date.now();
        $2kc.default.log("录屏时长==", e.endRecorderTime - e.startRecorderTime);
        e.endRecorderTime;
        e.startRecorderTime;
      });
      $2kc.default.log("停止录屏");
      e.channelObj.getGameRecorderManager().stop();
      $2kc.default.sendMsg($2KDefine.Msg.recorderStop);
    }
  }, {
    key: "getRecordTime",
    value: function getRecordTime() {
      return this.endRecorderTime - this.startRecorderTime;
    }
  }, {
    key: "shareVideo",
    value: function shareVideo() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
      if (!this.video_path) {
        return void $2kc.default.err("无录制视频");
      }
      var t = this;
      this.channelObj.shareAppMessage({
        channel: "video",
        title: t.title,
        imageUrl: "",
        query: "",
        extra: {
          videoPath: t.video_path,
          videoTopics: t.videoTopics
        },
        success() {
          t.channelObj.showToast({
            title: "分享成功"
          });
          t.endRecorderTime = 0;
          t.startRecorderTime = 0;
          $2kc.default.sendMsg($2KDefine.Msg.recorderDone);
          var a = $2kc.default.todayStr();
          var n = $2kc.default.getData("shareVideoTimes", {});
          $2kc.default.log("准备发放奖励", n);
          var o = parseInt(n[a] || 0);
          if (o < 5) {
            o++;
            n[a] = o;
            $2kc.default.saveData("shareVideoTimes", n);
            $2kc.default.log("发奖励");
            e && e();
          }
        },
        fail(e) {
          t.channelObj.showToast({
            title: "分享视频失败"
          });
          $2kc.default.err(e);
          $2kc.default.err("分享取消");
          t.endRecorderTime = 0;
          t.startRecorderTime = 0;
          $2kc.default.sendMsg($2KDefine.Msg.recorderFail);
        }
      });
    }
  }]);
  return l;
}($2pvzChannelWeb.pvzChannelWeb);
exports.pvzChannelTT = exp_pvzChannelTT;
exp_pvzChannelTT.videoWatchTimes = 0;
exp_pvzChannelTT.API_EventType = {
  active: "active",
  active_register: "active_register",
  game_addiction: "game_addiction"
};
exp_pvzChannelTT.API_clickid = null;